package Chapter05.cak;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, Integer> cases = new HashMap<String, Integer>(); // 存储病例数量的Map

        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1. 添加病例");
            System.out.println("2. 统计病例");
            System.out.println("3. 退出");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("请输入地区名称：");
                    String region = scanner.next();
                    System.out.println("请输入新增病例数量：");
                    int num = scanner.nextInt();
                    if (cases.containsKey(region)) {
                        cases.put(region, cases.get(region) + num);
                    } else {
                        cases.put(region, num);
                    }
                    System.out.println("病例添加成功！");
                    break;
                case 2:
                    System.out.println("请输入地区名称（输入all查看全部地区）：");
                    String input = scanner.next();
                    if (input.equals("all")) {
                        for (String r : cases.keySet()) {
                            System.out.println(r + " - " + cases.get(r));
                        }
                    } else {
                        if (cases.containsKey(input)) {
                            System.out.println(input + " - " + cases.get(input));
                        } else {
                            System.out.println("该地区没有病例。");
                        }
                    }
                    break;
                case 3:
                    System.out.println("程序已退出。");
                    return;
                default:
                    System.out.println("无效的选择，请重新输入。");
                    break;
            }
        }
    }
}
